
#include "Hdev.h"
#include <algorithm>
#include "HalconCpp.h"
#include "HTuple.h"
#include <map>
#include <mutex>
#include <string>
#include <QString>
#include "AppDataDef.h"
#include "mtp.h"

#ifndef __APPLE__
  #include <hdevengine/HDevEngineCpp.h>
#else
  #include <HDevEngineCpp/HDevEngineCpp.h>
#endif

using namespace HalconCpp;
using namespace HDevEngineCpp;


 Hdev::Hdev()
 {}

 Hdev::Hdev(QString fileFullPath):IHalcon(fileFullPath)
 { }

 Hdev::~Hdev()
 {}

 void Hdev::GetImgProResult(
	 IN HObject const& Image, IN HObject const& InRegion,
	 OUT HObject& ResultRegion, OUT HObject& CenterCross, OUT HObject& ResultXld, OUT HObject& ImageReduced,
	 OUT HObject& SearchContourXld, OUT HObject& PointCrossXld,
	 IN HTuple ModelID, IN HTuple MetrologyHandle, IN HTuple Mat, IN HTuple miniScore, IN HTuple ImgProcessType,
	 IN HTuple  StandOffsetX, IN HTuple StandOffsetY,
	 IN HTuple  StandImgPosX, IN HTuple StandImgPosY, IN HTuple StandImgPosAngle,
	 IN HTuple RotateCenterImgX, IN HTuple  RotateCenterImgY,
	 IN HTuple ManualBCX, IN HTuple ManualBCY, IN HTuple ManualBCR,
	 IN HTuple  TrayOffsetX, IN HTuple  TrayOffsetY, IN HTuple  TrayOffsetR, IN HTuple  orientation,
	 OUT HTuple* iResult, HTuple* findRow, HTuple* findColumn, HTuple* findAngle, HTuple* findScale, HTuple* findScore,
	 HTuple* OffsetX, HTuple* OffsetY, HTuple* OffsetR)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(GetImgProResult));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(InRegion), InRegion);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ModelID), ModelID);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(MetrologyHandle), MetrologyHandle);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(Mat), Mat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(miniScore), miniScore);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ImgProcessType), ImgProcessType);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(StandOffsetX), StandOffsetX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(StandOffsetY), StandOffsetY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(StandImgPosX), StandImgPosX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(StandImgPosY), StandImgPosY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(StandImgPosAngle), StandImgPosAngle);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgX), RotateCenterImgX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgY), RotateCenterImgY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCX), ManualBCX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCY), ManualBCY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCR), ManualBCR);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(TrayOffsetX), TrayOffsetX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(TrayOffsetY), TrayOffsetY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(TrayOffsetR), TrayOffsetR); 
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(orientation), orientation);
		 call.Execute();

		 ResultRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(ResultRegion));
		 CenterCross = ParamHandler<HObject>::GetParameter(call, ToSTR(CenterCross));
		 ResultXld = ParamHandler<HObject>::GetParameter(call, ToSTR(ResultXld));
		 ImageReduced = ParamHandler<HObject>::GetParameter(call, ToSTR(ImageReduced));
		 SearchContourXld = ParamHandler<HObject>::GetParameter(call, ToSTR(SearchContourXld));
		 PointCrossXld = ParamHandler<HObject>::GetParameter(call, ToSTR(PointCrossXld));

		 *iResult = ParamHandler<HTuple>::GetParameter(call, ToSTR(iResult));
		 *findRow = ParamHandler<HTuple>::GetParameter(call, ToSTR(findRow));
		 *findColumn = ParamHandler<HTuple>::GetParameter(call, ToSTR(findColumn));
		 *findAngle = ParamHandler<HTuple>::GetParameter(call, ToSTR(findAngle));
		 *findScale = ParamHandler<HTuple>::GetParameter(call, ToSTR(findScale));
		 *findScore = ParamHandler<HTuple>::GetParameter(call, ToSTR(findScore));

		 *OffsetX = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetX));
		 *OffsetY = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetY));
		 *OffsetR = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetR));
     }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }

 void Hdev::GetImgProResultMark(
	 IN HObject const& Image, IN HObject const& InRegion,
	 OUT HObject& OutRegion, OUT HObject& CenterCross, OUT HObject& ResultXld, OUT HObject& ImageReduced,
	 OUT HObject& SearchContourXld, OUT HObject& PointCrossXld,
	 IN HTuple ModelID, IN HTuple miniScore, IN HTuple MetrologyHandle, IN HTuple UpMat, IN HTuple DwMat, IN HTuple ImgProcessType,
	 IN HTuple RotateCenterImgX, IN HTuple  RotateCenterImgY,	 
	 IN HTuple  UpCenterX, IN HTuple UpCenterY,
	 IN HTuple  SlotIndex, IN HTuple  SlotImgPosX, IN HTuple SlotImgPosY, IN HTuple SlotImgPosAngle,
	 IN HTuple  Cam2NozzleDisX, IN HTuple Cam2NozzleDisY, IN HTuple UpDwCamAngleFixedDiff,
	 IN HTuple  Cam2NozzleDisBCX, IN HTuple Cam2NozzleDisBCY, IN HTuple UpDwCamAngleFixedDiffBC,
	 IN HTuple  NozzleMarkX, IN HTuple NozzleMarkY,
	 IN HTuple ManualBCX, IN HTuple ManualBCY, IN HTuple ManualBCR,
	 OUT HTuple* iResult, HTuple* findRow, HTuple* findColumn, HTuple* findAngle, HTuple* findScale, HTuple* findScore,
	 HTuple* OffsetX, HTuple* OffsetY, HTuple* OffsetR)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(GetImgProResultMark));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(InRegion), InRegion);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ModelID), ModelID);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(miniScore), miniScore);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(MetrologyHandle), MetrologyHandle);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpMat), UpMat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwMat), DwMat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ImgProcessType), ImgProcessType);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgX), RotateCenterImgX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgY), RotateCenterImgY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCenterX), UpCenterX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCenterY), UpCenterY);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(SlotIndex), SlotIndex);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(SlotImgPosX), SlotImgPosX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(SlotImgPosY), SlotImgPosY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(SlotImgPosAngle), SlotImgPosAngle);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(Cam2NozzleDisX), Cam2NozzleDisX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(Cam2NozzleDisY), Cam2NozzleDisY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpDwCamAngleFixedDiff), UpDwCamAngleFixedDiff);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(Cam2NozzleDisBCX), Cam2NozzleDisBCX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(Cam2NozzleDisBCY), Cam2NozzleDisBCY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpDwCamAngleFixedDiffBC), UpDwCamAngleFixedDiffBC);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(NozzleMarkX), NozzleMarkX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(NozzleMarkY), NozzleMarkY);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCX), ManualBCX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCY), ManualBCY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ManualBCR), ManualBCR);

		 call.Execute();

		 OutRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(OutRegion));
		 CenterCross = ParamHandler<HObject>::GetParameter(call, ToSTR(CenterCross));
		 ResultXld = ParamHandler<HObject>::GetParameter(call, ToSTR(ResultXld));
		 ImageReduced = ParamHandler<HObject>::GetParameter(call, ToSTR(ImageReduced));
		 SearchContourXld = ParamHandler<HObject>::GetParameter(call, ToSTR(SearchContourXld));
		 PointCrossXld = ParamHandler<HObject>::GetParameter(call, ToSTR(PointCrossXld));

		 *iResult = ParamHandler<HTuple>::GetParameter(call, ToSTR(iResult));
		 *findRow = ParamHandler<HTuple>::GetParameter(call, ToSTR(findRow));
		 *findColumn = ParamHandler<HTuple>::GetParameter(call, ToSTR(findColumn));
		 *findAngle = ParamHandler<HTuple>::GetParameter(call, ToSTR(findAngle));
		 *findScale = ParamHandler<HTuple>::GetParameter(call, ToSTR(findScale));
		 *findScore = ParamHandler<HTuple>::GetParameter(call, ToSTR(findScore));

		 *OffsetX = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetX));
		 *OffsetY = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetY));
		 *OffsetR = ParamHandler<HTuple>::GetParameter(call, ToSTR(OffsetR));
	 }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }


 void Hdev::RotateCenterMove(
	 IN HTuple ReMat,IN HTuple RobotPosX1, IN HTuple RobotPosY1, IN HTuple  RobotPosX2,IN HTuple RobotPosY2, 
	 IN HTuple RotateCenterImgX, IN HTuple  RotateCenterImgY,  OUT HTuple* MovedCenterImgX, HTuple* MovedCenterImgY)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(RotateCenterMove));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ReMat), ReMat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgX), RotateCenterImgX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RotateCenterImgY), RotateCenterImgY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RobotPosX1), RobotPosX1);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RobotPosY1), RobotPosY1);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RobotPosX2), RobotPosX2);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(RobotPosY2), RobotPosY2);
		 call.Execute();
		 *MovedCenterImgX = ParamHandler<HTuple>::GetParameter(call, ToSTR(MovedCenterImgX));
		 *MovedCenterImgY = ParamHandler<HTuple>::GetParameter(call, ToSTR(MovedCenterImgY));

	 }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }


 void  Hdev::Get2DCode(IN HObject const& Image, HObject const& InRegion, OUT HObject& OutRegion, HObject& OutXld, IN HTuple& DataCodeHandle, HTuple iType, OUT HTuple* strCode, HTuple* iError)
 {
	 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(Get2DCode));
	 HDevEngineCpp::HDevProcedureCall call(procedure);

	 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
	 ParamHandler<HObject>::SetParameter(call, ToSTR(InRegion), InRegion);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(DataCodeHandle), DataCodeHandle);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(iType), iType);
	 call.Execute();

	 OutRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(OutRegion));
	 OutXld = ParamHandler<HObject>::GetParameter(call, ToSTR(OutXld));
	 *strCode = ParamHandler<HTuple>::GetParameter(call, ToSTR(strCode));
	 *iError = ParamHandler<HTuple>::GetParameter(call, ToSTR(iError));
 }

 void Hdev::CropImage(IN HObject const& Image,
	 IN HObject& Roi,
	 OUT HObject& OutImage,
	 OUT HObject& CodeImage,
	 IN HTuple ImgGroup)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(CropImage));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(ImgGroup), ImgGroup);
		 ParamHandler<HObject>::SetParameter(call, ToSTR(Roi), Roi);
		 call.Execute();
		 OutImage = ParamHandler<HObject>::GetParameter(call, ToSTR(OutImage));
	     CodeImage = ParamHandler<HObject>::GetParameter(call, ToSTR(CodeImage));
	 }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }


 void Hdev::GetStdImgPoint(IN HObject const& Image, IN HObject const& Region,
	 OUT HObject& OutRegion, HObject& OutXld,
	 IN HTuple iType, IN HTuple HandleID, IN HTuple Mat, IN HTuple Para,
	 IN HTuple CalibDataID, HTuple CameraPara, HTuple Pose,
	 OUT HTuple* findRow, HTuple* findColumn, HTuple* findAngle, HTuple* iError)
 {
	 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(GetStdImgPoint));
	 HDevEngineCpp::HDevProcedureCall call(procedure);
	 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
	 ParamHandler<HObject>::SetParameter(call, ToSTR(Region), Region);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(iType), iType);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(HandleID), HandleID);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Mat), Mat);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Para), Para);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(CalibDataID), CalibDataID);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(CameraPara), CameraPara);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Pose), Pose);

	 call.Execute();

	 OutRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(OutRegion));
	 OutXld = ParamHandler<HObject>::GetParameter(call, ToSTR(OutXld));

	 *findRow = ParamHandler<HTuple>::GetParameter(call, ToSTR(findRow));
	 *findColumn = ParamHandler<HTuple>::GetParameter(call, ToSTR(findColumn));
	 *findAngle = ParamHandler<HTuple>::GetParameter(call, ToSTR(findAngle));
	 *iError = ParamHandler<HTuple>::GetParameter(call, ToSTR(iError));
 }

 void Hdev::ProcessMetrologyResult(IN HTuple iType, IN HTuple MetrologyHandle, OUT HTuple* Row, HTuple* Column, HTuple* Angle, HTuple* iResult)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(ProcessMetrologyResult));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(MetrologyHandle), MetrologyHandle);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(iType), iType);
		 call.Execute();
		 *Row = ParamHandler<HTuple>::GetParameter(call, ToSTR(Row));
		 *Column = ParamHandler<HTuple>::GetParameter(call, ToSTR(Column));
		 *Angle = ParamHandler<HTuple>::GetParameter(call, ToSTR(Angle));
		 *iResult = ParamHandler<HTuple>::GetParameter(call, ToSTR(iResult));
	 }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }

 void Hdev::CalculateOffset(
	 IN HTuple UpMat, IN HTuple DwMat,
	 IN HTuple UpCenterX, IN HTuple UpCenterY,
	 IN HTuple DwCenterX, IN HTuple DwCenterY,
	 IN HTuple UpMarkX,   IN HTuple UpMarkY, IN HTuple UpMarkR,
	 IN HTuple UpPotoMarkWx, IN HTuple UpPotoMarkWy,
	 IN HTuple DwMarkX, IN HTuple DwMarkY, IN HTuple DwMarkR,
	 IN HTuple PotoPos1Wx, IN HTuple PotoPos1Wy,
	 IN HTuple PotoPos2Wx, IN HTuple PotoPos2Wy,
	 IN HTuple NozzleMarkX, IN HTuple NozzleMarkY,
	 IN HTuple UpCamera2NozzleBCX, IN HTuple UpCamera2NozzleBCY, IN HTuple UpCamera2NozzleBCR,
	 OUT HTuple& CamNozzleWx, OUT HTuple& CamNozzleWy, OUT HTuple& CamNozzleWr)
 {
	 try
	 {
		 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(CalculateOffset));
		 HDevEngineCpp::HDevProcedureCall call(procedure);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpMat), UpMat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwMat), DwMat);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCenterX), UpCenterX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCenterY), UpCenterY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwCenterX), DwCenterX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwCenterY), DwCenterY);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpMarkX), UpMarkX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpMarkY), UpMarkY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpMarkR), UpMarkR);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpPotoMarkWx), UpPotoMarkWx);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpPotoMarkWy), UpPotoMarkWy);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwMarkX), DwMarkX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwMarkY), DwMarkY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(DwMarkR), DwMarkR);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(PotoPos1Wx), PotoPos1Wx);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(PotoPos1Wy), PotoPos1Wy);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(PotoPos2Wx), PotoPos2Wx);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(PotoPos2Wy), PotoPos2Wy);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(NozzleMarkX), NozzleMarkX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(NozzleMarkY), NozzleMarkY);

		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCamera2NozzleBCX), UpCamera2NozzleBCX);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCamera2NozzleBCY), UpCamera2NozzleBCY);
		 ParamHandler<HTuple>::SetParameter(call, ToSTR(UpCamera2NozzleBCR), UpCamera2NozzleBCR);

		 call.Execute();

		 CamNozzleWx = ParamHandler<HTuple>::GetParameter(call, ToSTR(CamNozzleWx));
		 CamNozzleWy = ParamHandler<HTuple>::GetParameter(call, ToSTR(CamNozzleWy));
		 CamNozzleWr= ParamHandler<HTuple>::GetParameter(call, ToSTR(CamNozzleWr));

	 }
	 catch (HDevEngineException e)
	 {
		 std::string text = e.Message();
		 //log(text.data());
		 LOG_DEBUG(GetmtpLogger(), text);
	 }
 }

	 void Hdev::DefenceError(IN HObject const& Image, IN HObject const& InRegion, 
		 OUT HObject& OutRegion, HObject& OKRegion, HObject& NGRegion, HObject& OutXld,
		 IN HTuple iType, HTuple HandleID, HTuple CalibDataID, HTuple  CameraPara, HTuple  Pose,
		 IN HTuple InSlotState, HTuple StdX, HTuple StdY, HTuple StdR1, HTuple StdR2,
		 IN HTuple  X_N, HTuple  X_P, HTuple  Y_N, HTuple  Y_P, HTuple  R_N, HTuple  R_P,
		 OUT HTuple* DistanceX, HTuple* DistanceY, HTuple* DutR, HTuple* NGSlot, HTuple* OutSlotState,
		 OUT HTuple* ReType, HTuple* ReStdX, HTuple* ReStdY, HTuple* CoordX, HTuple* CoordY,HTuple* iError)
 {
	 HDevEngineCpp::HDevProcedure procedure(GetProgram(m_ResourcePath + m_HdevName), ToSTR(DefenceError));
	 HDevEngineCpp::HDevProcedureCall call(procedure);
	 ParamHandler<HObject>::SetParameter(call, ToSTR(Image), Image);
	 ParamHandler<HObject>::SetParameter(call, ToSTR(InRegion), InRegion);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(iType), iType);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(HandleID), HandleID);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(CalibDataID), CalibDataID);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(CameraPara), CameraPara);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Pose), Pose);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(InSlotState), InSlotState);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(StdX), StdX);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(StdY), StdY);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(StdR1), StdR1);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(StdR2), StdR2);

	 ParamHandler<HTuple>::SetParameter(call, ToSTR(X_N), X_N);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(X_P), X_P);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Y_N), Y_N);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(Y_P), Y_P);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(R_N), R_N);
	 ParamHandler<HTuple>::SetParameter(call, ToSTR(R_P), R_P);

	 call.Execute();

	 OutRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(OutRegion));
	 OKRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(OKRegion));
	 NGRegion = ParamHandler<HObject>::GetParameter(call, ToSTR(NGRegion));
	 OutXld = ParamHandler<HObject>::GetParameter(call, ToSTR(OutXld));

	 *DistanceX = ParamHandler<HTuple>::GetParameter(call, ToSTR(DistanceX));
	 *DistanceY = ParamHandler<HTuple>::GetParameter(call, ToSTR(DistanceY));
	 *DutR = ParamHandler<HTuple>::GetParameter(call, ToSTR(DutR));

	 *NGSlot = ParamHandler<HTuple>::GetParameter(call, ToSTR(NGSlot));
	 *OutSlotState = ParamHandler<HTuple>::GetParameter(call, ToSTR(OutSlotState));

	 *ReType = ParamHandler<HTuple>::GetParameter(call, ToSTR(ReType));
	 *ReStdX = ParamHandler<HTuple>::GetParameter(call, ToSTR(ReStdX));
	 *ReStdY = ParamHandler<HTuple>::GetParameter(call, ToSTR(ReStdY));

	 *CoordX = ParamHandler<HTuple>::GetParameter(call, ToSTR(CoordX));
	 *CoordY = ParamHandler<HTuple>::GetParameter(call, ToSTR(CoordY));

	 *iError = ParamHandler<HTuple>::GetParameter(call, ToSTR(iError));
 }

 //ParamHandler<HObject>::SetParameter(call, ToSTR(),);
 //ParamHandler<HTuple>::SetParameter(call, ToSTR(), );
 //= ParamHandler<HObject>::GetParameter(call, ToSTR());
 //= ParamHandler<HTuple>::GetParameter(call, ToSTR());